package com.cn.zsc.config;

import com.cn.zsc.service.ChangeOrderStatus;
import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RocketMqCofig {


    @Bean(initMethod = "start", destroyMethod = "shutdown")
    public DefaultMQProducer producer(){
        DefaultMQProducer producer = new
                DefaultMQProducer("paymentGroup");
        producer.setNamesrvAddr("localhost:9876");
        return producer;
    }

    @Bean(initMethod = "start", destroyMethod = "shutdown")
    public DefaultMQPushConsumer consumer(@Qualifier("messageListener") ChangeOrderStatus messageListener){
        DefaultMQPushConsumer consumer = new DefaultMQPushConsumer("paymentConsumerGroup");
        consumer.setNamesrvAddr("localhost:9876");
        try {
            consumer.subscribe("payment","*");
            consumer.registerMessageListener(messageListener);
        } catch (MQClientException e) {
            e.printStackTrace();
        }
        return consumer;
    }
}
